package com.ziven.common.widget.index;


import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.ziven.common.widget.R;
import com.ziven.common.widget.WidgetUtils;
import com.ziven.easygo.util.ResourceUtils;

/**
 * @author Ziven
 */
public class BubbleLayout extends AppCompatTextView {

    private int bubbleHeight;

    public BubbleLayout(@NonNull Context context) {
        this(context, null);
    }

    public BubbleLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BubbleLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        if(getBackground() == null) {
            setTextColor(ResourceUtils.getColor(R.color.common_background_color));
            GradientDrawable bg = new GradientDrawable();
            bg.setColor(ResourceUtils.getColor(R.color.common_title_enable_color));
            bg.setShape(GradientDrawable.RECTANGLE);
            bg.setCornerRadius(WidgetUtils.dimenInt("4dp"));
            setBackground(bg);
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int oldBubbleHeight = bubbleHeight;
        bubbleHeight = getMeasuredHeight();
        if(oldBubbleHeight == 0) {
            setVisibility(GONE);
        }
    }

    public int getBubbleHeight() {
        return bubbleHeight;
    }
}
